<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>文件上传</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/reset.css">
<!--公共样式结束-->
<!--公共JS开始-->
<script src="__PUBLIC__/Js/jquery.min.js"></script>
<!--公共JS结束-->
<!--ztree结束-->
<!--uploadify开始-->
<script src="__PUBLIC__/Plugins/Etfile/Uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<style type="text/css">
	body {
		overflow:hidden;
	}
	.uploadBtn {
		position:relative;
	}
	.upload_btn_select {
		background-color:#09C;
		border:none;
		text-align:center;
		color:#FFF;
		padding:2px 10px;
		text-align:center;
		width: 100%;
	}
	.upload_btn_select:hover {
		background-color: #F90;
		border:none;
	}
	#uploadOk {
		display:none;
		padding:5px 10px;
		background-color:#090;
		color:#FFF;
		text-align:center;
	}
	#uploadOk .btn {
		color:#FF0;
		cursor:pointer;
	}
	.uploadify-queue {
		display:none;
	}
	#uploadNow {
		display:none;
		background-color:#F90;
		color:#FFF;
		padding:5px 10px;
		text-align:center;
	}
</style>
<!--uploadify结束-->
</head>

<body>
	<div id="uploadOk">
		<span class="info">上传成功</span>，<span class="btn">重新上传</span>
	</div>
	<div id="uploadNow">
		......正在上传......
	</div>
	<div id="uploadBtn">
		<input id="file_upload" name="file_upload" type="file" multiple>
	</div>
<script type="text/javascript">
	$(function(){
		//全局JS变量配置
		var uploadObj = {};
		var folder_id = '';
		var folder_key = '';
		var filetype = '{$filetype}';
		if(filetype=='Images'){
			folder_id = 10;
			folder_key = 'Common/Images/';
		}else if(filetype=='Media'){
			folder_id = 12;
			folder_key = 'Common/Media/';
		}else if(filetype=='Flash'){
			folder_id = 11;
			folder_key = 'Common/Flash/';
		}else if(filetype=='File'){
			folder_id = 14;
			folder_key = 'Common/File/';
		}else{
			folder_id = 13;
			folder_key = 'Common/Other/';
		}
		
		//重新上传
		$('#uploadOk>.btn').on('click',function(){
			$('#uploadOk').hide();
			//$('#uploadBtn').show();
			$('#uploadBtn').css({'width':'100%','height':'auto'});
		});
		
		//上传文件按钮
		$('#file_upload').uploadify({
			'removeCompleted' : true,
			'multi' : false,
			'debug' : false,
			'width' : '100%',
			'fileObjName' : 'file', //定义上传数据处理文件中接收数据使用的文件对象名
			//'queueID' : 'uploadQueue', //上传文件列表的Id
			'auto'     : true, //是否自动上传
			'buttonClass' : 'upload_btn_select', //上传按钮的CSS样式
			'buttonText' : '选择文件...', //上传按钮显示的文字
			'fileSizeLimit' : '{$FL_maxSize}KB', //限制上传的大小
			'fileTypeDesc' : '可以上传图片、压缩文件、音频、视频、PDF', //可选择的文件类型的描述
			'fileTypeExts' : '*.gif; *.jpg; *.png; *.zip; *.rar; *.mp3; *.wav; *.avi; *.wmv; *.pdf; *.xls; *.xlsx', //选项允许你限制上传文件的类型
			'swf'      : '__PUBLIC__/Plugins/Etfile/Uploadify/uploadify.swf',
			'uploader' : '{$FL_UPLOAD_URL}',
			'formData'     : {
				'token'     : '{$token}', //token
			},
			'onUploadComplete' : function(file){
				//console.log(file);
				$('#uploadOk').show();
				$('#uploadNow').hide();
				

				$.get('__URL__/getLastFile/',{filetitle:file.name},function(data){
					$('#uploadOk').show();
					$('#uploadNow').hide();					
					if(data.lastFileKey==''){
						$('#uploadOk>.info').html('上传失败');
						$('#uploadOk>.btn').html('请重试');
					}else{
						$('#uploadOk>.info').html('上传成功');
						$('#uploadOk>.btn').html('重新上传');
						var dealFun = '{$dealFun}';
						if(window.parent.dealSelectFile && dealFun!=''){
							window.parent.dealSelectFile[dealFun](data);
						}
						if(window.parent.dealSelectFile && dealFun==''){
							window.parent.dealSelectFile(data);
						}
					}
				},'json');
			},
			'onUploadProgress' : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
				var n = parseInt((totalBytesUploaded/totalBytesTotal)*100);
				$('#uploadNow').html('......已上传'+n+'%......');
			},
			'onUploadStart' : function(file) {
				var filekey = Date.parse(new Date())+ parseInt((Math.random(900)+100));
				filekey = folder_key + filekey;
				
				uploadObj.folder_id = folder_id;
				uploadObj.filekey = filekey;
				uploadObj.title = file.name;
				
				$('#uploadNow').show();
				$('#uploadBtn').css({'width':'0px','height':'0px','overflow':'hidden'});
				
				$('#file_upload').uploadify('settings','formData',
					{
						'folder_id':folder_id,
						'key':filekey,
						'x:key':filekey,
						'x:title':encodeURIComponent(file.name)
					}
				);
				//console.log('start:'+file.name);
			}
		});
	});
</script>
</body>
</html>